package com.schoolcloud.social.controller.forum;

import com.schoolcloud.common.model.PageDTO;
import com.schoolcloud.common.model.R;
import com.schoolcloud.social.entity.SocPostCategory;
import com.schoolcloud.social.query.CategoryQuery;
import com.schoolcloud.social.service.SocPostCategoryService;
import com.schoolcloud.social.vo.SocPostCategoryTreeVO;
import com.schoolcolud.daomybatisplus.query.MpPageQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping("social/post/category")
public class SocPostCategoryController {
    private final SocPostCategoryService socPostCategoryService;
    @GetMapping("/page")
    public R<PageDTO<SocPostCategory>> getPostCategoryPage(CategoryQuery query) {
        PageDTO<SocPostCategory> page=socPostCategoryService.getPostCategoryPage(query);
        return R.ok(page);
    }
    @GetMapping("/tree-list")
    public R<List<SocPostCategoryTreeVO>> getPostCategoryTree() {
        List<SocPostCategoryTreeVO> list=socPostCategoryService.getPostCategoryTree();
        return R.ok(list);
    }
    @GetMapping("/parent/tree/list")
    public R<List<SocPostCategoryTreeVO>> getCategoryParentTreeList(){
        List<SocPostCategoryTreeVO> list=socPostCategoryService.getCategoryParentTreeList();
        return R.ok(list);
    }
    @PostMapping
    public R<Object> addPostCategory(@RequestBody SocPostCategory socPostCategory) {
        socPostCategoryService.save(socPostCategory);
        return R.ok();
    }
    @DeleteMapping("/{categoryId}")
    public R<Object> delPostCategory(@PathVariable String categoryId) {
        socPostCategoryService.removeById(categoryId);
        return R.ok();
    }
    @PutMapping
    public R<Object> modifyPostCategory(@RequestBody SocPostCategory socPostCategory) {
        socPostCategoryService.updateById(socPostCategory);
        return R.ok();
    }
    @GetMapping("/{categoryId}")
    public R<SocPostCategory> getPostCategory(@PathVariable String categoryId) {
        return R.ok(socPostCategoryService.getById(categoryId));
    }
}
